package com.com.knowledgepaymentmanagementsystem.controller.marketing;

import com.com.knowledgepaymentmanagementsystem.pojo.marketing.Scene;
import com.com.knowledgepaymentmanagementsystem.service.marketing.SceneService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/23 下午3:51
 */
@Api(tags = "场景营销")
@RestController
@CrossOrigin
@RequestMapping("/scene")
public class SceneController {

    @Autowired
    private SceneService sceneService;

    @ApiOperation(value = "查询场景营销",httpMethod = "POST",notes = "查询场景营销")
    @PostMapping("/find")
    public ResultUtil<List<Scene>> getScene(@RequestBody Scene scene){

        try {
            return new ResultUtil<List<Scene>>(200,"查询成功",sceneService.findScene(scene));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    @ApiOperation(value = "新增场景营销",httpMethod = "POST",notes = "新增场景营销")
    @PostMapping("/insert")
    public ResultUtil insertScene(@RequestBody Scene scene){

        try {
            return new ResultUtil<>(200,"新增成功",sceneService.insertScene(scene));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "修改场景营销",httpMethod = "PUT",notes = "修改场景营销")
    @PutMapping("/update")
    public ResultUtil updateScene(@RequestBody Scene scene){
        try {
            sceneService.updateScene(scene);
            return new ResultUtil<>(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

    @ApiOperation(value = "删除场景营销",httpMethod = "DELETE",notes = "删除场景营销")
    @DeleteMapping("/delete")
    public ResultUtil deleteScene(Integer id){
        try {
            sceneService.deleteeScene(id);
            return new ResultUtil<>(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }

}
